package com.tiza.xiaoyoubao.ui.fragment;

import android.os.Bundle;
import android.view.View;

import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.net.ApiHttpClient;
import com.tiza.xiaoyoubao.net.JsonCallback;
import com.tiza.xiaoyoubao.net.ResponseInfo;

import java.util.Map;

import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by mapple on 17/2/17.
 */

public class TaskFragment extends BaseFragment {

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_task;
    }

    @Override
    protected void initData() {


    }

    @Override
    protected void initView() {
        setToolbarTitle("已接任务");
        selectOver();
    }

    @OnClick({
            R.id.view_Advances_unComplete,
            R.id.view_Advances_Complete,
            R.id.view_Advances_ondo,
            R.id.view_tb_unComplete,
            R.id.view_tb_Complete,
            R.id.view_tb_ondo,
            R.id.view_browse_uncomplete,
            R.id.view_browse_complete,
            R.id.view_browse_ondo
    })
    public void onClick(View view) {
        Bundle args=new Bundle();
        switch (view.getId()) {
            case R.id.view_Advances_unComplete:
                args.putString("way","1");
                UIHelper.showAdvancesUnComplate(mActivity,args);
                break;
            case R.id.view_Advances_Complete:
                UIHelper.showAdvancesComplate(mActivity);
                break;
            case R.id.view_Advances_ondo:
                UIHelper.showAdvancesOnDo(mActivity);
                break;
            case R.id.view_tb_unComplete:
                args.putString("way","1");
                UIHelper.showTbUnComplate(mActivity,args);
                break;
            case R.id.view_tb_Complete:
                UIHelper.showTbComplate(mActivity);
                break;
            case R.id.view_tb_ondo:
                UIHelper.showTbOnDo(mActivity);
                break;

            case R.id.view_browse_uncomplete:
                args.putString("way","1");
                selectOver();
                UIHelper.showBrowseUnComplate(mActivity,args);
                break;
            case R.id.view_browse_complete:
                UIHelper.showBrowseComplate(mActivity);
                break;
            case R.id.view_browse_ondo:
                UIHelper.showBrowseOnDo(mActivity);
                break;
            default:
                break;

        }
    }
    private void selectOver() {
        ApiHttpClient.selectOver(this,
                new JsonCallback<String>(String.class,true) {

                    @Override
                    public void onBefore(Request request) {
                        super.onBefore(request);
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        toast("网络连接失败，请稍后重试");
                    }

                    @Override
                    public void onResponse(ResponseInfo<String> response) {
                        int code = response.getCode();
                        String message = response.getMessage();
                        if (code == 1) {
                            showWarnDialog(message);
                            return;
                        }
                        Map<String, Object> _map = response.getFirstEntity();
                    }

                    @Override
                    public void onAfter() {
                        super.onAfter();
                    }
                }
        );
    }
}
